/*
 * @Author: 贺楠 1071780426@qq.com
 * @Date: 2024-09-10 11:27:32
 * @LastEditors: 贺楠 1071780426@qq.com
 * @LastEditTime: 2024-09-11 11:57:38
 * @FilePath: \monitoring_system\src\components\testMachineManage\equipmentAddManage\index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import {
    saveMachineInfo, //保存
} from "@/api/testMachineManage/request.js";
export default {
    props: [
        "dialogVisible",
        "dialogTitle",
        "statusNum",
        "currentRow",
    ],
    data() {
        return {
            visible: "",
            loading: false,
            title: null,
            isLock: false,
            positionwnData: [], //万能机
            positionylData: [], //压力机
            positionkzkyData: [], //抗折抗压机
            positionlqData: [], //沥青设备
            positionlqhhlData: [], //沥青混合料设备

            positionwnObj: [{
                label: "5T",
                value: "5T"
            }, {
                label: "10T",
                value: "10T"
            }, {
                label: "20T",
                value: "20T"
            }, {
                label: "30T",
                value: "30T"
            }, {
                label: "60T",
                value: "60T"
            }, {
                label: "100T",
                value: "100T"
            }, ], //万能机
            positionylObj: [{
                label: "200T",
                value: "200T"
            }], //压力机
            positionkzkyObj: [{
                label: "1T",
                value: "1T"
            }, {
                label: "30T",
                value: "30T"
            }], //抗折抗压机

            positionlqObj: [{
                label: "针入度",
                value: "针入度"
            }, {
                label: "软化点",
                value: "软化点"
            }, {
                label: "延度仪",
                value: "延度仪"
            }], //沥青机
            positionlqhhlObj: [{
                label: "马歇尔仪",
                value: "马歇尔仪"
            }, {
                label: "沥青含量",
                value: "沥青含量"
            }, {
                label: "车辙仪",
                value: "车辙仪"
            }], //沥青混合料机
            dialogHeight: null,
            isEdit: false,
            btnShow: true,
            currentDetail: null,
            treeCheck: null
        };
    },
    watch: {
        dialogVisible: {
            handler(newVal) {
                if (newVal) {
                    this.visible = newVal;
                }
            },
            immediate: true,
        },
        dialogTitle: {
            handler(newVal) {
                if (newVal) {
                    this.title = newVal;
                }
            },
            immediate: true,
        },
        currentRow: {
            handler(newVal) {
                if (newVal) {
                    this.currentDetail = newVal;
                    if (this.statusNum != 1) {
                        this.getDetail({
                            fId: this.currentDetail.fId
                        })
                    }
                }
            },
            immediate: true,
        },
    },
    created() {
        window.addEventListener("resize", this.getHeight);
        this.getHeight();
    }, //获取页面高度自适应：

    destroyed() {
        window.removeEventListener("resize", this.getHeight);
        this.getHeight();
    },
    mounted() {
        this.userInfo = JSON.parse(sessionStorage.getItem("monitorBack-userInfo"));
        this.treeCheck = JSON.parse(sessionStorage.getItem("monitorBack-testMachineManage_treeCheck"));
        this.btnShow = true;
        this.getHeight();
    },
    methods: {
        getHeight() {
            var h = document.documentElement.clientHeight; //获取页面可见高度
            this.dialogHeight = h * 0.85 + "px";
        },
        handleSelect(key) {
            this.activeIndex = key;
        },
        closeDialog() {
            this.$emit("close");
        },
        // 新增设备
        addEquipment(status) {
            if (status == 0) { //万能机
                this.positionwnData.push({
                    machineType: "",
                    machineCode: "",
                    machineName: "",
                    machineModel: "万能机",
                    companyId:this.treeCheck.fCompanyid

                });

            } else if (status == 1) { //压力机
                this.positionylData.push({
                    machineType: "",
                    machineCode: "",
                    machineName: "",
                    machineModel: "压力机",
                    companyId:this.treeCheck.fCompanyid

                });

            } else if (status == 2) { //抗折抗压机
                this.positionkzkyData.push({
                    machineType: "",
                    machineCode: "",
                    machineName: "",
                    machineModel: "抗折抗压机",
                    companyId:this.treeCheck.fCompanyid

                });

            } else if (status == 3) { //沥青设备
                this.positionlqData.push({
                    machineType: "",
                    machineCode: "",
                    machineName: "",
                    machineModel: "沥青设备",
                    companyId:this.treeCheck.fCompanyid

                });

            } else if (status == 4) { //沥青混合料设备
                this.positionlqhhlData.push({
                    machineType: "",
                    machineCode: "",
                    machineName: "",
                    machineModel: "沥青混合料设备",
                    companyId:this.treeCheck.fCompanyid

                });

            }

        },
        // 删除设备
        deleteEquipment(index, row, status) {
            if (status == 0) { //万能机
                this.positionwnObj.map(item => {
                    if (item.fId == row.machineType.fId) {
                        item.disabled = false
                    } else if (item.fId == row.machineCode) {
                        item.disabled = false
                    }
                })
                this.positionwnData.splice(index, 1);

            } else if (status == 1) { //压力机
                this.positionylObj.map(item => {
                    if (item.fId == row.machineType.fId) {
                        item.disabled = false
                    } else if (item.fId == row.machineCode) {
                        item.disabled = false
                    }
                })
                this.positionylData.splice(index, 1);
            } else if (status == 2) { //抗折抗压机
                this.positionkzkyObj.map(item => {
                    if (item.fId == row.machineType.fId) {
                        item.disabled = false
                    } else if (item.fId == row.machineCode) {
                        item.disabled = false
                    }
                })
                this.positionkzkyData.splice(index, 1);
            } else if (status == 3) { //沥青设备
                this.positionlqObj.map(item => {
                    if (item.fId == row.machineType.fId) {
                        item.disabled = false
                    } else if (item.fId == row.machineCode) {
                        item.disabled = false
                    }
                })
                this.positionlqData.splice(index, 1);
            } else if (status == 4) { //沥青混合料设备
                this.positionlqhhlObj.map(item => {
                    if (item.fId == row.machineType.fId) {
                        item.disabled = false
                    } else if (item.fId == row.machineCode) {
                        item.disabled = false
                    }
                })
                this.positionlqhhlData.splice(index, 1);
            }
        },


        //设备型号选择
        selectEquipment(row, name, index, status) {
            if (status == 0) { //万能机
                this.positionwnData[index].machineName = "万能机" + name;
                this.positionwnData[index].machineCode = this.treeCheck.fProjectid + "-" + this.treeCheck.fEncode + "-WNJ" + name;
            } else if (status == 1) { //压力机
                this.positionylData[index].machineName = "压力机" + name;
                this.positionylData[index].machineCode = this.treeCheck.fProjectid + "-" + this.treeCheck.fEncode + "-YLJ" + name;
            } else if (status == 2) { //抗折抗压
                this.positionkzkyData[index].machineName = "万能机" + name;
                this.positionkzkyData[index].machineCode = this.treeCheck.fProjectid + "-" + this.treeCheck.fEncode + "-YLJ" + name;
            } else if (status == 3) { //沥青设备
                if (name == "针入度") {
                    this.positionlqData[index].machineName = name + "仪";
                    this.positionlqData[index].machineCode = this.treeCheck.fProjectid + "-" + this.treeCheck.fEncode + "-ZRD";
                } else if (name == "软化点") {
                    this.positionlqData[index].machineName = name + "仪";
                    this.positionlqData[index].machineCode = this.treeCheck.fProjectid + "-" + this.treeCheck.fEncode + "-RHD";
                } else if (name == "延度仪") {
                    this.positionlqData[index].machineName = name + "仪";
                    this.positionlqData[index].machineCode = this.treeCheck.fProjectid + "-" + this.treeCheck.fEncode + "-YDY";
                }
            } else if (status == 4) { //沥青混合料设备
                if (name == "马歇尔仪") {
                    this.positionlqhhlData[index].machineName = name + "稳定度仪";
                    this.positionlqhhlData[index].machineCode = this.treeCheck.fProjectid + "-" + this.treeCheck.fEncode + "-MXEY";
                } else if (name == "沥青含量") {
                    this.positionlqhhlData[index].machineName = name + "测量仪";
                    this.positionlqhhlData[index].machineCode = this.treeCheck.fProjectid + "-" + this.treeCheck.fEncode + "-LQHLY";
                } else if (name == "车辙仪") {
                    this.positionlqhhlData[index].machineName = name + "试验仪";
                    this.positionlqhhlData[index].machineCode = this.treeCheck.fProjectid + "-" + this.treeCheck.fEncode + "-CZY";
                }
            }

        },


        yj_saveForm() {
            // positionwnData: [],//万能机
            // positionylData: [],//压力机
            // positionkzkyData: [],//抗折抗压机
            // positionlqData: [],//沥青设备
            // positionlqhhlData: [],//沥青混合料设备
            // 合并设备
            var mergedArray = [...this.positionwnData, ...this.positionylData, ...this.positionkzkyData, ...this.positionlqData, ...this.positionlqhhlData];
            console.log(mergedArray);
            var tableData = []
            mergedArray.map(item => {
                if (item.machineType != "") {
                    tableData.push(item)
                }
            })
            this.saveForm(tableData);
        },
        // 保存
        saveForm(data) {
            this.loading = true;
            this.isLock = true
            saveMachineInfo(data)
                .then((res) => {
                    if (res.errcode == 0) {
                        this.loading = false;
                        this.visible = false;
                        this.$emit("refreshList");
                        this.$message.success("新增成功");
                        this.isLock = false
                    } else {
                        this.loading = false;
                        this.isLock = false
                        this.$message.error(res.msg);
                        console.log("接口报错");
                    }
                })
        },

    },
};